define(function(require, exports, module){
    window.routerObj ={
    	history:[]
    };
    var router;
	router = Backbone.Router.extend({
		routes: {
			":para": "debugger",   
		},
		setRouterObj:function(para){
			console.log(para)
			var localHref = window.location.href;
			var size = routerObj.history.length;
			if(routerObj.history[size-1] != localHref){
				routerObj.history.push(localHref);
			}
			// beforeId: "index", curId: "found"}
			routerObj.beforeId = routerObj.curId || 'found';
			routerObj.curId = para;
		},
        debugger:function(para){
            var obj = {
            	mId:para,
            	name:para,
            	type:para
            };
        	this.setRouterObj(para);
            this.loadPage(obj);
            share.blur(obj.mId);
        	share.blur(routerObj.beforeId);
        },
		loadPage:function(obj){

			var This=this,src = '{controller}'+obj.name+'.js';

			share.loading();
			require.async(src,function(controller){
                if(controller){
                	if(controller.ajaxBool){
                		controller.render();
                	}else{
                		controller.render();
            			share.showPage(obj.mId);
                	}
                }else{
                    This.page404();
                }
			});

            if(obj.type == 'index'){
                this.preloadTpl();
            };

		},
		
		preloadTpl:function(){
			// setTimeout(function(){
			// 	var This = this,src,navArray;
   			// 	navArray = ['signin','register','activity'];
			// 	require.async('{controller}userNav.js');
			// 	for(var i=0; i<navArray.length; i++){
			// 		src = '{controller}'+navArray[i]+'.js';
			// 		require.async(src);
			// 	}
			// },500);
		},
		page404:function(){
			// $('#page404').remove();
			// $('.page').hide();
			// $('body').append('<div id="page404">404 没有找到页面。即将调整到首页...</div>');
			// share.loading('hide')
			// setTimeout(function(){
   //              window.history.go(-1);
			// 	$('#page404').remove();
			// },2500)
		},
	});
	module.exports = router;
});

